package com.felix.algorithms.easy;

import java.util.HashSet;
import java.util.Set;

/**
 * UniqueMorseCodeWords
 *
 * @author xuejinhua
 * @date 2018/9/14 10:49
 */
public class UniqueMorseCodeWords {

    private static String[] morse = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};

    /**
     * Q804
     * @return
     */
    public static int solution(String[] words){
        Set<String> set = new HashSet<>();
        for (String word : words) {
            char[] chars = word.toCharArray();
            StringBuilder stringBuilder = new StringBuilder();
            for (char c : chars) {
                int index = c - 97;
                stringBuilder.append(morse[index]);
            }
            set.add(stringBuilder.toString());
        }
        return set.size();
    }

    public static void main(String[] args) {
        String[] words = {"gin", "zen", "gig", "msg"};
        System.out.println(solution(words));
    }
}
